composer-sample-networks
1. 创建business network
clone官方示例,获取Business Network Definitions
git clone https://github.com/hyperledger/composer-sample-networks.git
2. 安装 Lerna 来 build 该仓库文件
$ npm install -g lerna
3. bootstrap the repository
安装依赖,链接package(正如normal node.js package)
$ lerna bootstrap
4. 使用lerna一次性在所有packege中执行npm命令
$ lerna run test
自动生成打包好的.bna
文件
5. Bond Network
Bond债券 Network
The Bond Network allows the issuer of a bond to update the bond information whilst other members of the business network can only read the bond data.
- Participants Issuer Member
- Assets BondAsset
- Transactions PublishBond
The PublishBond transaction submitted by an Issuer participant will create a new BondAsset.
- Create a
Issuer
participant:
1 2 3 4 5
| { "$class": "org.acme.bond.Issuer", "memberId": "memberId:1", "name": "Billy Thompson" }
|
- Create a
Member
participant:
1 2 3 4 5
| { "$class": "org.acme.bond.Member", "memberId": "memberId:1", "name": "Jenny Jones" }
|
- Submit a
PublishBond
transaction:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| { "$class": "org.acme.bond.PublishBond", "ISINCode": "ISINCode:1234", "bond": { "$class": "org.acme.bond.Bond", "instrumentId": [], "exchangeId": [], "maturity": "2017-07-13T09:39:05.369Z", "parValue": 1000, "faceAmount": 1000, "paymentFrequency": { "$class": "org.acme.bond.PaymentFrequency", "periodMultiplier": 0, "period": "DAY" }, "dayCountFraction": "", "issuer": "resource:org.acme.bond.Issuer#memberId:1" } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| describe('#publish', () => {
it('should be able to publish a bond', () => {
const factory = businessNetworkConnection.getBusinessNetwork().getFactory();
const issuer = factory.newResource(namespace, 'Issuer', 'daniel.selman@example.com'); issuer.name = 'Dan Selman Holdings';
const paymentFrequency = factory.newConcept(namespace, 'PaymentFrequency'); paymentFrequency.periodMultiplier = 6; paymentFrequency.period = 'MONTH'; const bond = factory.newConcept(namespace, 'Bond'); bond.instrumentId = ['ACME']; bond.exchangeId = ['NYSE']; bond.maturity = new Date('2018-02-27T21:03:52+00:00'); bond.parValue = 1000; bond.faceAmount = 1000; bond.paymentFrequency = paymentFrequency; bond.dayCountFraction = 'EOM'; bond.issuer = factory.newRelationship(namespace, 'Issuer', issuer.$identifier);
const publishBond = factory.newTransaction(namespace, 'PublishBond'); publishBond.bond = bond; publishBond.ISINCode = 'US4592001014';
return businessNetworkConnection.getParticipantRegistry(namespace + '.Issuer') .then((issuerRegistry) => { return issuerRegistry.addAll([issuer]); }) .then(() => { return businessNetworkConnection.submitTransaction(publishBond); }) .then(() => { return businessNetworkConnection.getAssetRegistry(namespace + '.BondAsset'); }) .then((bondRegistry) => { return bondRegistry.get(publishBond.ISINCode); }) .then((newBondAsset) => { newBondAsset.ISINCode.should.equal(publishBond.ISINCode); }); }); });
|